/*
 * @Description: 分货结果DS
 * @Version: 1.0
 * @Autor: c-jack.qian
 * @Date: 2020-12-28 20:03:25
 * @LastEditors: c-jack.qian
 * @LastEditTime: 2021-04-08 16:30:19
 */
import { FieldType } from 'choerodon-ui/pro/lib/data-set/enum';
import commonConfigStore from '@common/config/commonConfig';
import { resetMonth } from '../utils/utilsFun';
import intl from 'utils/intl';
const O2_OM = process.env.NODE_ENV === 'development' ? '/o2om-c' : commonConfigStore.O2_OM;

const distributionResultDS = () => ({
    autoQuery: true,
    selection: 'multiple',
    primaryKey: 'id',
    transport: {
        read: config => {
            const { data } = config;
            const { distributionResultMonth } = data;
            // 截掉月份后面的时间
            const submitData = resetMonth(data,distributionResultMonth,'distributionResultMonth')
            return {
                ...config,
                data: {
                    ...submitData,
                },
                url: `${O2_OM}/v1/distribution-results`,
                method: 'get',
            };
        },
        destroy: config => {
            return {
                ...config,
                url: `${O2_OM}/v1/distribution-results`,
                method: 'delete',
            };
        },
    },
    fields: [
        {
            name: 'distributionResultMonth',
            type: FieldType.string,
            label: intl.get('dji.otc.om.view.field.orderType').d('月份'),
            required: true,
        },
        {
            name: 'shortageTypeMeaning',
            type: FieldType.string,
            label: intl.get('dji.otc.om.view.field.tagTypeB').d('类型'),
            required: true,
        },
        {
            name: 'regionName',
            type: FieldType.string,
            label: intl.get('dji.otc.om.view.field.tagName').d('大区'),
            required: true,
        },
        {
            name: 'areaName',
            type: FieldType.string,
            label: intl.get('dji.otc.om.view.field.tagName').d('小区'),
            required: true,
        },
        {
            name: 'businessGroupMeaning',
            type: FieldType.string,
            label: intl.get('dji.otc.om.view.field.tagDescription').d('渠道'),
        },
        {
            name: 'customerName',
            type: FieldType.string,
            label: intl.get('dji.otc.om.view.field.isStatementApplied').d('客户'),
        },
        {
            name: 'retailer',
            type: FieldType.string,
            label: intl.get('dji.otc.om.view.field.statementDisplayText').d('零售商'),
        },
        {
            name: 'productCode',
            type: FieldType.string,
            label: intl.get('dji.otc.om.view.field.isCreditApplied').d('料号'),
        },
        {
            name: 'productName',
            type: FieldType.string,
            label: intl.get('dji.otc.om.view.field.isInvoiceAssessApplied').d('产品名称'),
        },
        {
            name: 'warehouse',
            type: FieldType.string,
            label: intl.get('dji.otc.om.view.field.statementDisplayText').d('发货仓库'),
        },
        {
            name: 'totalQuantity',
            type: FieldType.string,
            label: intl.get('dji.otc.om.view.field.isCreditApplied').d('累计分货数量'),
        },
    ],
    queryFields: [
        {
            name: 'customerName',
            type: FieldType.string,
            label: intl.get('dji.otc.om.view.field.tagType').d('代理商'),
        },
        {
            name: 'productName',
            type: FieldType.string,
            label: intl.get('dji.otc.om.view.field.tagType').d('产品'),
        },
        {
            name: 'regionId',
            type: FieldType.number,
            label: intl.get('dji.otc.om.view.field.tagDescription').d('大区'),
            lookupCode: 'DJICM_CHOOSE_BIG_AREA',
        }, 
        {
            name: 'areaId',
            type: FieldType.number,
            label: intl.get('dji.otc.om.view.field.tagDescription').d('小区'),
            lookupCode: 'DJIOM_CHOOSE_SMALL_AREA',
        }, 
        {
            name: 'customerType',
            type: FieldType.string,
            label: '客户类型',
            lookupCode: 'DJISM.CUSTOMER_TYPE'
        },
        {
            name: 'distributionResultMonth',
            type: FieldType.month,
            label: '给货月份',
        },
    ],
});

const resultDetailDS = () => ({
    dataToJSON: 'normal',
    paging: false,
    selection: false,
    transport: {
        read: config => {
            const {resultId} = config.data
            return {
                ...config,
                url: `${O2_OM}/v1/distribution-result-details/${resultId}`,
                data:{},
                method: 'get',
            };
        },
    },
    fields: [
        {
            name: 'creationDate',
            type: FieldType.dateTime,
            label: intl.get('dji.otc.om.view.field.orderType').d('导入时间'),
            required: true,
        },
        {
            name: 'importMode',
            type: FieldType.string,
            label: intl.get('dji.otc.om.view.field.tagTypeB').d('导入方式'),
            required: true,
            lookupCode: 'DJISM.IMPORT_MODE',
        },
        {
            name: 'quantity',
            type: FieldType.string,
            label: intl.get('dji.otc.om.view.field.tagName').d('导入数量'),
            required: true,
        },
    ],
});

export { distributionResultDS, resultDetailDS };
